<?php

/*
	Class: PagepartsCategories

	About: Author
		Rich Joslin

	About: License
		<http://communit.as/docs/license>

	About: See Also
		- <Cts_Db_Table_Abstract>
*/
class PagepartsCategories extends Cts_Db_Table_Abstract {

	/* Group: Instance Variables */

	/*
		Variable: $_name
	*/
	protected $_name = 'pageparts_categories';

	/*
		Variable: $_primary
	*/
	protected $_primary = 'id';

	/* Group: Instance Methods */

	/*
		Function: getAll

		Returns: array of categories or an empty array
	*/
	function getAll() {
		$tmp_categories = $this->fetchAll();
		if (!is_null($tmp_categories)) {
			return $tmp_categories->toArray();
		} else {
			return array();
		}
	}

	/*
		Function: getOptions
			Gets an array of categories from the database.
			The array returned fits perfectly with Smarty's functions html_options, html_checkboxes, etc.

		Arguments:
			first_option (optional) - A string to describe the first entry in the returned array which will have a null value.

		Returns: array of category options
	*/
    public function getOptions($first_option = null) {
    	$options = array();
		if (!is_null($first_option)) {
	    	$options[''] = $first_option;
		}
    	$tmp_categories = $this->fetchAll(null, 'name');
    	foreach ($tmp_categories as $category) {
    		$options[$category->id] = $category->name;
    	}
    	return $options;
    }

}
